//
//  CommentViewController.m
//  News
//
//  Created by xalo on 16/3/7.
//  Copyright © 2016年 News. All rights reserved.
//

#import "CommentViewController.h"
#import "CommentTableViewCell.h"
#import "HTTPHelper.h"
#import "CommentModel.h"
#import <MJRefresh.h>

@interface CommentViewController ()

@property(nonatomic,strong)NSMutableArray *commentArray ;
@end

@implementation CommentViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"全部评论";
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"返回" style:(UIBarButtonItemStylePlain) target:self action:@selector(back)];
    
    [[HTTPHelper sharedManger] getPictureCommentWith:self.commentArray number:self.comments time:self.time block:^{
        
        [self.tableView reloadData];
    }];
    
    [self getDowmComment];
    
    self.tableView.rowHeight = 120;
    

   
}

#pragma mark - Table view data source

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return self.commentArray.count;
    
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    CommentTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Call" forIndexPath:indexPath];
    
    CommentModel *commdel = self.commentArray[indexPath.row];
    cell.commModel =commdel;
    
    return cell;
}

//下拉
-(void)getDowmComment {
    
    self.tableView.mj_footer = [MJRefreshAutoFooter footerWithRefreshingBlock:^{
        
        [[HTTPHelper sharedManger] getPictureCommentWith:self.commentArray number:self.comments time:self.time block:^{
            
            self.time++;
            
            
            [self.tableView reloadData];
            [self.tableView.mj_footer endEditing:YES];
            
        }];
    }];
    
}


-(NSMutableArray *)commentArray {
    
    if (!_commentArray) {
        _commentArray = [NSMutableArray array];
    }
    return _commentArray;
  }

-(void)back {
    
    
    [self dismissViewControllerAnimated:YES completion:nil];
    
}

@end
